package com.pomr.controller.test;

import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.pomr.util.common.SIMConnection;
/**
 * 
 * 类名称： sss
 * 创建人： Administrator
 * 创建时间：2018年5月8日 上午10:17:26
 * 类描述：
 */
public class sss {
	//java加密方法
	public static String MD5Encode(String origin, String charsetname) {
			String resultString = null;
			try {
				resultString = new String(origin);
				MessageDigest md = MessageDigest.getInstance("MD5");
				if (charsetname == null || "".equals(charsetname))
					resultString = SIMConnection.bytesToHexFun2(md.digest(resultString
							.getBytes()));
				else
					resultString = SIMConnection.bytesToHexFun2(md.digest(resultString
							.getBytes(charsetname)));
			} catch (Exception exception) {
			}
			return resultString;
		}


	 
	public static String getData(Object value){
			if(null == value)
				return "";
			else 
				return value.toString();
		}
	
	public static String createSign(Map<String, String> packageParams,String appSercet) throws Exception{
		StringBuffer sb = new StringBuffer();
		Set es = packageParams.entrySet();
		Iterator it = es.iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			String k = getData(entry.getKey());
			String v = getData(entry.getValue());
			if (null != v && !"".equals(v)) {
				sb.append(k + "=" + v + "&");
			}
		}
		sb.append("appSecret=" + appSercet);
		String sign = MD5Encode(sb.toString(), "UTF-8").toUpperCase();
		return sign;
	}//加密方式


	public static void main(String[] args){
		List<String> paramList = new LinkedList<String>();
		paramList.add(0, "11");
		paramList.add(0, "22");
		for(String s:paramList){
			System.out.println(s);
		}
		 }

}
